package org.vidi.amqp.pubsub;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.vidi.amqp.common.ConnectionUtils;
import org.vidi.amqp.common.Constants;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author vidi
 */
public class LogEmitDirect {
    public static void main(String[] args) {
        try (Connection connection = ConnectionUtils.newSingleConnection();
             Channel channel = connection.createChannel()) {
            channel.exchangeDeclare(Constants.DIRECT_EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

            for (int i = 0; i < Constants.MESSAGE_COUNT; i++) {
                String severity = i % 6 == 0 ? " INFO" : "ERROR";
                String message = severity + "Emit Log " + i;
                channel.basicPublish(Constants.DIRECT_EXCHANGE_NAME, severity, null, message.getBytes());
            }

        } catch (TimeoutException | IOException e) {
            e.printStackTrace();
        }
    }
}
